package cn.com.connected.controller;

import cn.com.connected.base.params.page.BaseSearchDto;
import cn.com.connected.base.params.page.PageResult;
import cn.com.connected.base.utils.IpTools;
import cn.com.connected.common.config.CurrentData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.com.connected.vo.DynamicVo;
import cn.com.connected.dto.DynamicDto;
import cn.com.connected.dto.search.DynamicSearchDto;
import cn.com.connected.service.DynamicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletRequest;


/**
 * 动态
 * @author sms
 * @email sms@live.com
 * @date 2025-04-10 16:15:14
 */
@Api(tags = "动态")
@RestController
@Slf4j
public class DynamicController extends BaseController  {

    @Autowired
    private DynamicService dynamicService;

    @ApiOperation(value="描述:动态添加 ok")
    @RequestMapping(value="/v1/dynamic",method= RequestMethod.POST)
    public DynamicVo dynamicAdd(@RequestBody @Validated DynamicDto dynamicDto, HttpServletRequest request) {
        dynamicDto.setIp(IpTools.getIpAddr(request));
//        dynamicDto.setIpCityName();
        return dynamicService.dynamicAdd(dynamicDto);
    }

    @ApiOperation(value="描述:动态详情 ok")
    @RequestMapping(value="/v1/dynamic/{id}",method= RequestMethod.GET)
    public DynamicVo dynamicInfo(@PathVariable("id") String id) {
        return dynamicService.dynamicInfo(id);
    }

//    @ApiOperation(value="描述:动态编辑 ing")
//    @RequestMapping(value="/v1/dynamic/{id}",method= RequestMethod.PUT)
//    public void dynamicEdit(@PathVariable("id") String id, @RequestBody @Validated DynamicDto dynamicDto) {
//            dynamicService.dynamicEdit(id,dynamicDto);
//    }

    @ApiOperation(value="描述:动态删除 ok")
    @RequestMapping(value="/v1/dynamic/{id}",method= RequestMethod.DELETE)
    public void dynamicDel(@PathVariable("id") String id) {
            dynamicService.dynamicDel(id);
    }

    @ApiOperation(value="描述:我的动态列表 ok")
    @RequestMapping(value="/v1/dynamics",method= RequestMethod.POST)
    public PageResult<DynamicVo> dynamics(@RequestBody BaseSearchDto<DynamicSearchDto> searchParams) {
        searchParams.getSearchOption().setMemberId(CurrentData.getMemberId());
        return dynamicService.dynamicPage(searchParams);
    }


}
